package org.ttjhome.db.dbo;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Version;

@Entity
@Table(name="Jobs")
public class Job implements Serializable{


	
	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column
    private Long id;
	
	@Version
	private int version;
	
	@Column(length=100)
	private String name;
	

	@ManyToOne()
	@JoinColumn(nullable=false)
	private Company company;
	
	
	@Column(length=150)
	private String filename;
	
	@Column(length=200)
	private String description;
	
	@Column(length=20)
	private String status ;
	

	@ManyToMany(fetch=FetchType.EAGER)
    @JoinTable(name="Job_Tags",
               joinColumns=@JoinColumn(name="JOB_ID"),
               inverseJoinColumns=@JoinColumn(name="TAG_ID"))
    private Set<Tag> tags = new HashSet<Tag>();

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(length=200)
	private String url;
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public int getVersion() {
		return version;
	}

	public void setVersion(int version) {
		this.version = version;
	}

	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	public String getFilename() {
		return filename;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public Set<Tag> getTags() {
		return tags;
	}

	public void setTags(Set<Tag> tags) {
		this.tags = tags;
	}

	public String getTagsAsString(){
		if(tags==null||tags.size()==0)
			return "";
		String result="";
		for(Tag tag:tags){
			result+=tag+" ";
		}
		return result;
	}
	
	public String toString() {
		return "{filename:" + this.filename+",name:"+this.name+",description:"+this.description + ",url:" + this.url + ",id:"
				+ this.id + "}";
	}

}
